package org.ravenhearte.hardboild.gui;

import com.jme.scene.state.BlendState;
import com.jme.system.DisplaySystem;

public class TransparentImageButton extends ImageButton {
	public TransparentImageButton(String name, int width, int height) {
		super(name, width, height);
		
		DisplaySystem display = DisplaySystem.getDisplaySystem();
		
		// to handle texture transparency:
		// create a blend state
		final BlendState bs = display.getRenderer().createBlendState();
		// activate blending
		bs.setBlendEnabled(true);
		// set the source function
		bs.setSourceFunctionAlpha(BlendState.SourceFunction.SourceAlpha);
		// set the destination function
		bs.setDestinationFunctionAlpha(BlendState.DestinationFunction.OneMinusSourceAlpha);
		// set the blend equation between source and destination
		bs.setBlendEquation(BlendState.BlendEquation.Subtract);
		bs.setTestEnabled(true);
		bs.setTestFunction(BlendState.TestFunction.GreaterThan);
		// activate the blend state
		bs.setEnabled(true);
		// assign the blender state to the quad
		spatial.setRenderState(bs);
	}
}
